package com.leetcode.problems017;


import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/
 * @Date 2021/11/20 14:34
 * @Author ghery
 * @Version V1.0
 */
public class Solution {
    /**
     * 数字对应的字符串
     */
    static String[] phoneNums = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};

    private List<String> resList = new ArrayList<>();

    public List<String> letterCombinations(String digits) {
        if(digits == null || digits.length() == 0){
            return new ArrayList<>();
        }
        letterCombinations(digits,0,new StringBuilder());
        return resList;
    }

    public void letterCombinations(String digits,int index,StringBuilder res) {
        if(index == digits.length()){
            resList.add(res.toString());
            return;
        }
        int curNum = digits.charAt(index) - '0';
        String phoneNumStr = phoneNums[curNum];
        for (int j = 0; j < phoneNumStr.length(); j++) {
            //当前的数字为
            res.append(phoneNumStr.charAt(j));
            letterCombinations(digits,index + 1,res);
            res.delete(res.length() - 1,res.length());
        }
    }
    public static void main(String[] args) {

        String digits = "23";

        System.out.println(new Solution().letterCombinations(digits));
    }
}
